

*directory to be changed 
 cd "/Users/eliemurard/Dropbox/immigration welfare attitudes-Freeman/dofile_1718/replication JEG/"

run "semipar_X.do" 
	
use "replication_data_JEG.dta", clear 
	
	global regional  ln_pop_nat_value ln_gdp_PPP_percap unemp2064 ln_N_skill_ratio

	
	cap drop __*
	keep if ess_sample ==1
	keep if sample_Z_pca_score ==1
	g p=1
		
	collapse (mean) Z_pca_score $regional pct_2010  pct_2010_sq  (sum) p , by( country nuts2 year_ess )
	
	egen id_nuts2      = group(country nuts2) 
	egen id_nuts2_year = group(country nuts2 year) 
    egen id_country_yearess = group(country year_ess)
    qui ta id_country_yearess, gen(id_country_yearess__) 

***************************************************************************
** Figure 3: non parametrique graph
***************************************************************************

	semiparX Z_pca_score  $regional id_country_yearess__*  [aw=p]  , nonpar(pct_2010) bwidth(0.1) cluster(id_nuts2 )  ///
			kernel(epanechnikov)  ci level(90)  degree(1)   xtitle("Share of immigrants in 2010")   ytitle("Index of Welfare attitudes")
	 graph save main, replace

***************************************************************************
** Figure 4
***************************************************************************
	
use "replication_data_JEG.dta", clear 

		cap drop __*
		keep if ess_sample ==1
		keep if sample_Z_pca_score ==1
		g p=1	
		collapse (mean) Z_pca_score $regional pct_2010  pct_2010_sq   (sum) p , by( country nuts2 year_ess high_welfarestate )
		
		egen id_nuts2      = group(country nuts2) 
		egen id_nuts2_year = group(country nuts2 year) 
		egen id_country_yearess = group(country year_ess)
		qui ta id_country_yearess, gen(id_country_yearess__)
		
		qui semiparX Z_pca_score  $regional id_country_yearess__*  [aw=p] if high_welfarestate ==1 ///
		,kernel(epanechnikov)  ci level(90)  nonpar(pct_2010)   $option_nonpar  cluster(id_nuts2 ) title(High Welfare-State)  xtitle("Share of immigrants in 2010")   ytitle("Index of Welfare attitudes")
		graph save high_welf, replace
			
		qui semiparX Z_pca_score  $regional id_country_yearess__*  [aw=p] if high_welfarestate ==0 & pct_2010< 0.4 , ///
		kernel(epanechnikov)  ci level(90)  nonpar(pct_2010)   $option_nonpar  cluster(id_nuts2 ) title(Low Welfare-State)  xtitle("Share of immigrants in 2010")   ytitle("Index of Welfare attitudes")
		graph save low_welf, replace
		
		graph combine high_welf.gph low_welf.gph, ycommon 		 graphregion(color(white)) 
